package validator

import "regexp"

type alphaType struct{}

var alphaReg = regexp.MustCompile("^[A-z0-9_]+$")

func (t *alphaType) Validate(name string, val string, required bool) (bool, string) {
	if val == "" {
		if required {
			return false, name + "不能为空"
		}
		return true, ""
	}

	if !alphaReg.MatchString(val) {
		return false, name + "应为英文字母、数字、下划线组合"
	}

	return true, ""
}
